Trade Policy and Global Sourcing: A Rationale for Tariff Escalation

Pol Antràs, Teresa C. Fort, Agustín Gutiérrez (gutierrez25@wisc.edu) , and Felix Tintelnot
============================================================================================

Overview
----------------------------
This Readme documents the necessary steps to replicate all results in the paper and appendix of "Trade Policy and Global Sourcing: A Rationale for Tariff Escalation" by Pol Antràs, Teresa C. Fort, Agustín Gutiérrez, and Felix Tintelnot.

All non-theoretical results in the paper use publicly available data and thus tables and figures in the paper can be reproduced using the scripts in the Code directory. 

We run the code using a personal computer and the University of Chicago computer cluster. We therefore recommend reading this document fully before running any of the scripts since they must run in a specific order. 

This document is organized as follows:
	1. Data Availability Statements.
		1.1. Details on each Data Source. 	   
		1.2. Dataset list 			    

	2. Computational requirements
		2.1. Runtime requirements
		2.2. Software requirements

	3. Descriptions of replication package and programs 
		3.1. Instructions for running the programs 
		3.2. List of figures and tables 	    

	4. References 					 





1. Data Availability Statements
--------------------------------

We use only publicly available data. All the necessary data to replicate the paper are included in the replication package. 

### 1.1 Detail on each Data Source

	1. The World input-output tables are included in this replication package. The raw  data are from Groningen Growth and Development Centre (Timmer, Dietzenbacher, Los, Stehrer, and de Vries, 2015)  and can be downloaded from https://www.rug.nl/ggdc/valuechain/wiod/wiod-2016-release. To download relevant data, click "WIOT Tables Excel". (Last accessed: April 15, 2021).

	2. The concordance data are from multiple sources:
		2.1. Concordance between  HS and BEC comes from the United Nations - Classifications on economic statistics. The raw data can be downloaded from https://unstats.un.org/unsd/classifications/Econ, scroll down to the HS - SITC/BEC table and click on the data in row HS 2012  column BEC Rev. 5. (Last accessed: July 19, 2023).

		2.2. The concordance data from HS to NAICS comes from Pierce and Schott (2012), and can be accessed here: https://sompks4.github.io/sub_data.html. Refer to their replication package for more details. (Last accessed: September  12, 2023).

		2.3. The concordance data for NACE Rev 2 to NAICS comes from the United Nations, and can be accessed here: https://unstats.un.org/unsd/classifications/Econ. (Last accessed: April 26, 2021).

	3. Population data are from The CEPII Gravity database (Conte, Cotterlaz, Mayer, 2022). The raw data can be accessed here: http://www.cepii.fr/cepii/en/bdd_modele/bdd_modele_item.asp?id=8.  (Last accessed: January  2, 2023).

	4. Tariff data are from multiple sources:
		4.1. We use the data from Shapiro (2020). These includes bilateral tariff data on goods classified as final or intermediate goods. The data can be accessed here: https://joseph-s-shapiro.com/data.html. Refer to his replication package for more details. (Last accessed: May 17, 2020).

		4.2. We use tariff data from the United States International Trade Commission. Go to https://www.usitc.gov. Click on "Trade & Tariff"/Tariff/Tariff Annual Data. Then select and manually download tariff data from 2010 until 2019. (Last accessed: August 17, 2023).

		4.3. Applied MFN tariffs are from the World Trade Organization. Go to http://tariffdata.wto.org/ReportersAndProducts.aspx select all Reporters and all goods. (Last accessed: July 19, 2023).

		4.4. We use the tariff data in Fajgelbaum et al. (2020). The raw data can be found here: http://www.econ.ucla.edu/pfajgelbaum/. Click on "Tariff Data 2018". Refer to their replication package for more details. (Last accessed: October 28, 2019).

		4.5. We use tariff data from Bown (2019). The raw data can be found here: https://www.piie.com/blogs/trade-and-investment-policy-watch/us-china-trade-war-guns-august. (Last accessed: February 22, 2021).

		4.6. We use tariff data from Iowa State University -- Center for Agricultural and Rural Development. The raw data can be accessed here: https://www.card.iastate.edu/china/trade-war-data/. (Last accessed: February 10, 2021).

	5. The markup data correspond to the estimates in Baqaee and Farhi (2020). We use their estimates under the Cobb-Douglas specification,  file "Markups_CD_Compustat.dta" in their replication package. The raw data can be accessed here: https://doi.org/10.7910/DVN/CT5MZN. Refer to their replication for more details. (Last accessed: March 30, 2019).

	6.  Trade flow data are from the US Census Bureau.
		6.1. We use the API service of the US Census to scrape monthly data on US imports. The replication package includes a script that scrapes the data (see ../Code/0_Model_Parameters_and_Moments/prepare_imports.do). However, for replication purposes we include the scraped data in the Data directory.   

		6.2. We use annual US import data (quantity and value, HS10) from the US Census, USA Trade. The raw data can be found here: https://usatrade.census.gov. To replicate our data follow these steps. Click the "My reports" tab, and the button "Import report definition". Import the file "census_imports_2015.prd" included in this replication package. After that the website will generate the necessary data. (Last accessed: February 11, 2021).
		
		6.3. We use annual US import data (value by country and country-groups, HS10) from the US Census, USA Trade. The raw data can be found here: https://usatrade.census.gov. Country-groups were created manually in the US Census interface, these includes countries covered under the Least Developed Beneficiary Developing Countries in the Generalized System of Preferences, the WTO Agreement on Trade in Civil Aircraft, NAFTA, the Caribbean Basin Initiative, the African Growth and Opportunity Act, the Caribbean Basin Trade Partnership Act, the Dominican Republic-Central America Free Trade Agreement, and the WTO Pharmaceutical Agreement. To replicate our data follow these steps. Click the "My reports" tab, and the button "Import report definition". Import the file "census_imports_country_2015.prd" included in this replication package. After that the website will generate the necessary data.  (Last accessed: February 11, 2021).

		6.4. We use annual US export data (value by country, HS6) from the US Census, USA Trade. The raw data can be found here: https://usatrade.census.gov. To replicate our data follow these steps. Click the "My reports" tab, and the button "Import report definition". Import the file "census_exports_hs6.pdr" included in this replication package. After that the website will generate the necessary data. (Last accessed: February 11, 2021).

	Note: The US Census provides data using the latest version of the HS classification. As of today they provide data based on HS 2022 while the data we used correspond to HS 2017.


### 1.2. Dataset list

|-----------------------------------------------------------|-------------------------------------------------|----------------------|
| Data File                               	            | Source 					      | Provided 	     |
|-----------------------------------------------------------|-------------------------------------------------|----------------------|
| Data/WIOT2014_Nov16_ROW.xlsx   		  	    | Groningen Growth and Development Centre         | Yes      	     |
| Data/HS2012-17-BEC5_08_Nov_2018.xlsx	  		    | United Nations     			      | Yes		     |
| Data/hs_sic_naics_imports_89_121_20220627.dta 	    | Pierce and Schott (2012)   	 	      | Yes   		     |
| Data/NACE Rev 2 - NAICS 2007 - as per October 1st 2010.xls| United Nations     			      | Yes     	     |
| Data/Gravity_V202211.dta		  		    | CEPII     				      | Yes   		     |
| Data/tariffs_intermediate_final.dta		  	    | Shapiro (2020)    			      | Yes   		     |
| Data/importer_names.dta	   		    	    | Shapiro (2020)     			      | Yes   		     |
| Data/2010_Tariff_Database_v11.txt	   		    | United States International Trade Commission    | Yes   		     |
| Data/2011_Tariff_Database_v11.txt	   		    | United States International Trade Commission    | Yes   		     |
| Data/2012_Tariff_Database_v11.txt	   		    | United States International Trade Commission    | Yes   		     |
| Data/2013_Tariff_Database_v11.txt	   		    | United States International Trade Commission    | Yes   		     |
| Data/2014_Tariff_Database_v11.txt	   		    | United States International Trade Commission    | Yes   		     |
| Data/2015_Tariff_Database_v11.txt	   		    | United States International Trade Commission    | Yes   		     |
| Data/2016_Tariff_Database_v11.txt	   		    | United States International Trade Commission    | Yes   		     |
| Data/2017_Tariff_Database_v11.txt	   		    | United States International Trade Commission    | Yes   		     |
| Data/2018_Tariff_Database_v11.txt	   		    | United States International Trade Commission    | Yes   		     |
| Data/2019_Tariff_Database_v11.txt	   		    | United States International Trade Commission    | Yes   		     |
| Data/tariff_database_2017.xlsx 			    | United States International Trade Commission    | Yes   		     | 
| Data/tariff_database_2018.xlsx 			    | United States International Trade Commission    | Yes   		     |
| Data/tariff_database_2019.xlsx 		            | United States International Trade Commission    | Yes   		     |
| Data/Applied_MFN_Tariffs_1.txt	   		    | WTO     					      | Yes   		     |
| Data/Applied_MFN_Tariffs_2.txt	   		    | WTO     					      | Yes   		     |
| Data/Applied_MFN_Tariffs_3.txt	   		    | WTO     					      | Yes   		     |
| Data/Applied_MFN_Tariffs_4.txt	   		    | WTO     					      | Yes   		     |
| Data/Applied_MFN_Tariffs_5.txt	   		    | WTO     					      | Yes   		     |
| Data/Applied_MFN_Tariffs_6.txt	   		    | WTO     					      | Yes   		     |
| Data/Applied_MFN_Tariffs_7.txt	   		    | WTO     					      | Yes   		     |
| Data/Applied_MFN_Tariffs_8.txt	   		    | WTO     					      | Yes   		     |
| Data/Applied_MFN_Tariffs_9.txt	   		    | WTO     					      | Yes   		     |
| Data/Applied_MFN_Tariffs_10.txt	   		    | WTO     					      | Yes   		     |
| Data/Applied_MFN_Tariffs_11.txt	   		    | WTO     					      | Yes   		     |
| Data/Applied_MFN_Tariffs_12.txt	   		    | WTO     					      | Yes   		     |
| Data/Applied_MFN_Tariffs_13.txt	   		    | WTO     					      | Yes   		     |
| Data/Applied_MFN_Tariffs_14.txt	   		    | WTO     					      | Yes   		     |
| Data/Applied_MFN_Tariffs_15.txt	   		    | WTO     					      | Yes   		     |
| Data/baqee_farhi_markups.dta 				    | Baqaee and Farhi (2020)   	 	      | Yes        	     |
| Data/fajgelbaum_us_import_tariffs_2018.dta		    | Fajgelbaum et al (2020)     		      | Yes   		     |
| Data/Guns of August bown-2019-09-20.xlsx	            | Bown (2019)     				      | Yes   		     |
| Data/bown_tariff_data.xlsx 		 		    | Bown (2019)     				      | Yes   		     |
| Data/card_tariff_database.xlsx	   		    | Center for Agricultural and Rural Development   | Yes   		     || Data/imports_YEAR_MONTH_HScode.dta			    | US census  				      | Yes 		     |
| Data/census_imports_country_2015.csv		            | US census     				      | Yes   		     |
| Data/census_imports_country_2015.prd		            | US census     				      | Yes   		     |
| Data/census_imports_2015.csv 	   	 		    | US census     				      | Yes   		     |
| Data/census_imports_2015.prd 	   	 		    | US census     				      | Yes   		     |
| Data/census_exports_hs6.csv	   		    	    | US census     				      | Yes   		     |
| Data/census_exports_hs6.pdr	   		    	    | US census     				      | Yes   		     |
|-----------------------------------------------------------|-------------------------------------------------|----------------------|


2. Computational requirements
------------------------------
The replication files can be run on a 2022 laptop with 24GB of RAM, M2 Apple chip, and a 64-bit operating system with the exception of the Grid Search exercises that were ran on the University of Chicago computer cluster Midway2. To learn more about Midway2 computer visit https://rcc.uchicago.edu/support-and-services/midway2. 


### 2.1. Runtime requirements
The scripts that run on our personal computer are relatively fast, with the longest running time of about 20 minutes. The running time of the script depends heavily on two things: (i) whether we initialize the algorithm from multiple initial points; and (ii) Knitro multiple algorithm option.  The running time can be reduced if either of these options is deactivated. For the latter please read Knitro manual and modify the option file kintro12.opt.

The Grid search exercises take around 36 hours to complete and are subject to interruption, for example, when the servers are rebooted, or, sometimes when the sbatch mode skips running some iterations for no apparent reason in perfectly good code. For 99 percent of the combinations of parameters we explore, the running time is around 20 minutes. You can reduce the running time by deactivating the multiple initial points option or the multiple algorithm in Knitro. However, we advise against doing this, Knitro's multiple algorithm option ensures finding a maximum in each iteration while starting from multiple initial points avoids finding local maxima.

 
### 2.2. Software requirements

- Stata (code was last run with version SE18)

- Matlab (code was last run with MATLAB R2023_a)

- Knitro: 
   - Code was last run on the personal computer with Knitro 13.2.0.
   - Code was last run on UChicago cluster with Knitro 12.1.0.


3. Descriptions of replication package and programs
----------------------------------------------------
The replication package comes with four directories: (i) Code; (ii) Data; (iii) Output; (iv) Temp. 

The Data folder, as specified above, contains all the publicly available data necessary to replicate our results. Manipulation of the data and auxiliary output will be stored in the Temp folder. All the results in the paper will be stored in the Output folder. For the figures and tables in the paper look at ../Output/figures and ../Output/tables, respectively.

The Code directory contains all the scripts to replicate our results. Inside the Code folder there are 6 separate scripts that execute all the other programs. These scripts are named with a letter follow by the word Main_. The letter a_, b_, up to f_ capture the order in which these scripts need to be executed. Inside each script there is a description of the programs it calls and the output it generates. 

The Code directory also contains 6 sub-directories numbered 1_ to 6_. The Main scripts described in the  previous paragraph call programs inside these sub-directories. However, if you prefer to execute the programs separately, you can use the numbering in the folders and the conveniently named script Main inside them to execute the programs in the appropriate order. 


### 3.1. Instructions for running the programs 
Start by copying the set of folders provided in the replication package as they appear in the replication package in your preferred directory. The folder Data will have the necessary data to start running the codes. If you prefer to download the data yourself use the information in Section 1.1 in this document to do so and save the downloaded data in the Data directory. 

From your Code directory execute the scripts in the following order:
	* Step 1: Execute the Stata code a_Main_Parameters_Moments.do. This script:
		   	a) Takes data from CEPII and WIOT to construct the data moments used to calibrate the model. 
			
			b) Uses data from Baqaee and Farhi (2020) to construct demand elasticities base on markup estimates.

			c) Uses trade flow responses to tariff changes to estimate demand elasticities.

	* Step 2: Execute the Malab code b_Main_ModelEstimation_OptimalPolicy_Counterfactual.m. This script:
			a) Uses the data moments and estimates the model for all combinations of parameters considered in the paper.
				Note: Calls scripts in subdirectory: 1_Estimation_Model/Main_AFGT_estimation.m
			
			b) Given the estimated parameters computes the first- and second-best policies implied by the model.				
				Note: Calls scripts in subdirectory: 2_Optimal_Policy/First_Best/Main_AFGT_FirstBest.m
				      Calls scripts in subdirectory: 2_Optimal_Policy/Second_Best/Main_AFGT_SndBest.m
			
			c) Compute welfare counterfactuals from Trump tariff war.
				Note: Calls scripts in subdirectory: 3_Counterfactual/Main_AFGT_counterfactual.m
		
	  Note: Inside each of the "Main_" listed above there are option parameters you can adjust. These appear as follows"
		% Specify Program
		info.save       = 1;                            % = 1 to save results
		info.initval    = 1;                            % = 1 starts from previous run 
		info.multistart = 1;                            % = 1 for multiple random initial points
		info.ms_runs    = 50;                           % # of runs in multi-start	

	* Step 3: Run the Grid Search exercises in the computer clusters of your institution. Copy the entire replication directory to the cluster.
			a) From the linux terminal go the subdirectory Code/4_Grid_Search_EES/6_1_Gammas/

			b) Execute from the linux terminal the sbatch file c_Main_GridSearch_ScaleElast.sbatch.
				This will run the grid search exercise computing the second-best policy in the small open economy for different values of the scale elasticities and downstream labor share.
				It saves the results in Code/4_Grid_Search_EES/6_1_Gammas/Temp.

			c) Copy the files in Code/4_Grid_Search_EES/6_1_Gammas/Temp into your computer (same path) for what follows in Step 4.

			a) From the linux terminal go the subdirectory Code/4_Grid_Search_EES/6_2_Elasticities/

			b) Execute from the linux terminal the sbatch file d_Main_GridSearch_DemandElast.sbatch.
				This will run the grid search exercise computing the second-best policy in the small open economy for different values of the demand elasticities and downstream labor share.
				It saves the results in Code/4_Grid_Search_EES/6_2_Elasticities/Temp.

			c) Copy the files in Code/4_Grid_Search_EES/6_2_Elasticities/Temp in your computer (same path) for what follows in Step 4.

	   Note: We recommend copying the entire replication directory to the cluster despite only running a few scripts. This is because the script calls for the set of estimated parameters in Step 2.a. If you prefer to copy just the script related to the grid search remember to adjust the paths and include the estimated parameters saved in ../Output/AFGT_Param_tab2_row2.mat.

	* Step 4: In your personal computer from the Code directory execute the Matlab program e_Main_Tables_Grid_Search.m. This script:
			a) Reads files from Code/4_Grid_Search_EES/6_1_Gammas/Temp  and Code/4_Grid_Search_EES/6_2_Elasticities/Temp.

			b) Produces statistics about Tariff escalation in the grid search exercises. 

			c) Exports tables to the output folder.

	    Note: Calls scripts in subdirectory: 5_Tables/Statistics_and_Tables_DemandElasticity.m
					         5_Tables/Statistics_and_Tables_ScaleElasticity.m

	* Step 5: In your personal computer from the Code directory execute the Stata program f_Main_Figures.do. This script:
			a) Computes Figure 1 using Shapiro (2020) data.

			b) Takes the results in the grid search exercise and produces Figure 2 and Figure 3 (as well as the figures in the Appendix).

			c) Computes US tariffs to RoW on final-goods and inputs, and RoW tariffs to US on final-goods and inputs. 
				Note: This last step produces Figure 4  in the paper.

	   Note: Calls scripts in subdirectory: 6_Figures/


### 3.2. List of figures and tables

|------------------|-------------------------------------------------------------|----------------------------------------------|
| Figure/Table #   | Program                                                     | Output file                                  | 
|------------------|-------------------------------------------------------------|----------------------------------------------|
| Figure 1         | Code/f_Main_Figures.do 				         | Output/figures/te_country.eps    	        |                                                     		
| Figure 2         | Code/f_Main_Figures.do                                      | Output/figures/te_alpha_17-all.eps		|
| Figure 3         | Code/f_Main_Figures.do     				 | Output/figures/te_alpha_elast_50-all.eps     |                 
| Figure 4(a)      | Code/f_Main_Figures.do     				 | Output/figures/bar_chart_us.eps              |                                               
| Figure 4(b)      | Code/f_Main_Figures.do     				 | Output/figures/bar_chart_row.eps             |                                                                         
| Figure C.1       | Code/f_Main_Figures.do     				 | Output/figures/te_alpha_combine-all.eps      |                                               
| Figure C.2       | Code/f_Main_Figures.do     				 | Output/figures/te_ration_se_bya.eps          |                                               
| Figure C.3       | Code/f_Main_Figures.do     				 | Output/figures/te_alpha_elast_combine-all.eps|    
| Figure C.4       | Code/f_Main_Figures.do     				 | Output/figures/te_ration_se_elast_bya.eps    |
| Figure D.1(a)    | Code/f_Main_Figures.do     				 | Output/figures/bar_chart_us_noweight.eps     |
| Figure D.2(b)    | Code/f_Main_Figures.do     				 | Output/figures/bar_chart_row_noweight.eps    |                                               
|------------------|-------------------------------------------------------------|----------------------------------------------|
| Table 1          | Code/b_Main_ModelEstimation_OptimalPolicy_Counterfactual.m  | Output/tables/Calibrated_parameters.xlsx     |
| 		   | Code/b_Main_ModelEstimation_OptimalPolicy_Counterfactual.m  | Output/tables/Calibrated_moments.xlsx        | 
| Table 2          | Code/b_Main_ModelEstimation_OptimalPolicy_Counterfactual.m  | Output/tables/FirstBest_policy.xlsx          | 
| 		   | Code/b_Main_ModelEstimation_OptimalPolicy_Counterfactual.m  | Output/tables/SecondBest_policy.xlsx         | 
| Table 3          | Code/b_Main_ModelEstimation_OptimalPolicy_Counterfactual.m  | Output/tables/FirstBest_policy.xlsx          | 
| 		   | Code/b_Main_ModelEstimation_OptimalPolicy_Counterfactual.m  | Output/tables/SecondBest_policy.xlsx         |
| Table 4          | Code/b_Main_ModelEstimation_OptimalPolicy_Counterfactual.m  | Output/tables/CounterfactualTrump.xlsx       |
| Table C.1        | Follows from Table C.9   					 |					        |
| Table C.2        | Follows from Table 2 and Table 3   			 |			    		        |
| Table C.3        | Code/e_Main_Tables_Grid_Search.m    			 | Output/tables/tablec3.xlsx 		        |
| Table C.4        | Code/e_Main_Tables_Grid_Search.m    			 | Output/tables/tablec4.xlsx                   |
| Table C.5        | Code/e_Main_Tables_Grid_Search.m                            | Output/tables/tablec5.xlsx                   |
| Table C.6        | Code/e_Main_Tables_Grid_Search.m                            | Output/tables/tablec6.xlsx                   |
| Table C.7        | Code/e_Main_Tables_Grid_Search.m    			 | Output/tables/tablec7.xlsx 		        |
| Table C.8        | Code/e_Main_Tables_Grid_Search.m    			 | Output/tables/tablec8.xlsx    		|
| Table C.9        | Code/b_Main_ModelEstimation_OptimalPolicy_Counterfactual.m  | Output/tables/Calibrated_parameters.xlsx 	|
| Table D.1        | Code/a_Main_Parameters_Moments.do    			 | Output/tables/trade_elasticities.tex 	|	
| Table D.2        | Code/a_Main_Parameters_Moments.do    			 | Output/tables/sum_elast_pool.tex 		|
| Table D.3        | Taken from Bartelme et al. (2021)    			 |			    		        |
|------------------|-------------------------------------------------------------|----------------------------------------------|


Note: 
	1. Most tables are created in Excel files, hence some formatting from Excel tables to Latex is necessary. 
	2. All output files listed above are included in the replication package.


4. References		
-------------

Bartelme, Costinot, Donaldson, and Rodríguez- Clare. 2021. “The textbook case for industrial policy: Theory meets data,” Technical Report, MIT, Mimeo 2021.

Baqaee, and Farhi. 2020. “Productivity and Misallocation in General Equilibrium,” Quarterly Journal of Economics, February 2020, 135 (1), 105–163.

Bown. 2019. US-China Trade War: The Guns of August. PIIE Trade and Investment Policy Watch blog, Peterson Institute for International Economics (August 26).

Conte, Cotterlaz, and Mayer. 2022. "The CEPII Gravity database," CEPII Working Paper N°2022-05, July 2022. 

Fajgelbaum, Goldberg, Kennedy, Khandelwal. 2020. "The Return to Protectionism," Quarterly Journal of Economics, vol. 135.

Li, M. (2018) CARD Trade War Tariffs Database. https://www.card.iastate.edu/china/trade-war-data/ (Accessed 02-10-2021)

Pierce, and Schott. 2012. "A Concordance Between Ten-Digit U.S. Harmonized System Codes and SIC/NAICS Product Classes and Industries ," Journal of Economic and Social Measurement 37(1-2):61-96.

Shapiro. 2020. “The Environmental Bias of Trade Policy,” The Quarterly Journal of Economics, 12, 136 (2), 831–886.

Timmer, Dietzenbacher, Los, Stehrer, and de Vries. 2015. "An Illustrated User Guide to the World Input–Output Database: the Case of Global Automotive Production" , Review of International Economics., 23: 575–605.
